home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / BlobMgr / Library Folder / Drag.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-21  |  2.8 KB  |  128 lines  |  [TEXT/KAHL]

  1. # include    "BlobMgr.h"
  2.  
  3.  
  4.  
  5. /* -------------------------------------------------------------------- */
  6. /*                    Blob Tracking and Dragging Routines                    */
  7. /* -------------------------------------------------------------------- */
  8.  
  9.  
  10. /*
  11.  * Blob dragging variables.  See discussion of DragGrayRgn in
  12.  * the WIndow Manager section of Inside Mac.  The defaults for the
  13.  * limit and slop rects are inappropriate and really should be set
  14.  * by the application.
  15.  */
  16.  
  17. static Rect    blobLimitRect = { -30000, -30000, 30000, 30000 };
  18. static Rect    blobSlopRect = { -30000, -30000, 30000, 30000 };
  19. static short    blobAxis = noConstraint;
  20.  
  21.  
  22. /*    Set blob dragging limit and slop rectangles    */
  23.  
  24. pascal void
  25. SetBDragRects (Rect *limitRect, Rect *slopRect)
  26. {
  27.     blobLimitRect = *limitRect;
  28.     blobSlopRect = *slopRect;
  29. }
  30.  
  31.  
  32. /*    get current blob dragging limit and slop rectangles    */
  33.  
  34. pascal void
  35. GetBDragRects (Rect *limitRect, Rect *slopRect)
  36. {
  37.     *limitRect = blobLimitRect;
  38.     *slopRect = blobSlopRect;
  39. }
  40.  
  41.  
  42. /*    Set blob dragging axis constraints    */
  43.  
  44. pascal void
  45. SetBDragAxis (short axis)
  46. {
  47.     blobAxis = axis;
  48. }
  49.  
  50.  
  51. /*    Get current blob dragging axis constraints    */
  52.  
  53. pascal short
  54. GetBDragAxis (void)
  55. {
  56.     return (blobAxis);
  57. }
  58.  
  59.  
  60. /*
  61.  * Track blob by dragging an outline of the indicated part around
  62.  * until the mouse button is released.    Return the difference between
  63.  * the starting and ending x and y coordinates in the low and high
  64.  * order words of the result.
  65.  */
  66.  
  67. pascal long
  68. TrackBlob (BlobHandle b, short partCode, Point startPoint,
  69.             Rect * limitRect, Rect * slopRect, short axis)
  70. {
  71. RgnHandle    rgn;
  72. Rect        limit, bounds;
  73. long        result;
  74.  
  75.     rgn = BCalcRegion (b, partCode);
  76.     /*
  77.      * Adjust the limit rectangle so the outline of the dragged regiopn
  78.      * always fits completely within the bounds rectangle
  79.      */
  80.     limit = *limitRect;
  81.     bounds = (**rgn).rgnBBox;
  82.     limit.left += startPoint.h - bounds.left;
  83.     limit.top += startPoint.v - bounds.top;
  84.     limit.right -= bounds.right - startPoint.h - 1;
  85.     limit.bottom -= bounds.bottom - startPoint.v - 1;
  86.     
  87.     result = DragGrayRgn (rgn, startPoint, &limit, slopRect, axis, nil);
  88.     DisposeRgn (rgn);
  89.     return (result);
  90. }
  91.  
  92.  
  93. /*
  94.  * Track a blob, using the default limit and slop rects
  95.  */
  96.  
  97. pascal long
  98. DTrackBlob (BlobHandle b, short partCode, Point startPoint)
  99. {
  100.  
  101.     return (TrackBlob (b, partCode, startPoint,
  102.                                 &blobLimitRect, &blobSlopRect, blobAxis));
  103. }
  104.  
  105.  
  106. /*
  107.  * Drag a blob by tracking it, and then moving it to the point
  108.  * where the mouse button was released.
  109.  */
  110.  
  111. pascal void
  112. DragBlob (BlobHandle b, Point startPoint,
  113.                     Rect *limitRect, Rect *slopRect, short axis)
  114. {
  115. long    result;
  116.  
  117.     result = TrackBlob (b, inFullBlob, startPoint, limitRect, slopRect, axis);
  118.     if ((result != badDragResult) && (result != 0))
  119.         OffsetBlob (b, inFullBlob, LoWord (result), HiWord (result));
  120. }
  121.  
  122.  
  123. pascal void
  124. DDragBlob (BlobHandle b, Point startPoint)
  125. {
  126.     DragBlob (b, startPoint, &blobLimitRect, &blobSlopRect, blobAxis);
  127. }
  128.